/*
 *    Copyright (c) 2018-2025, nart All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: nart
 */

package com.nai365.nart.blockchain.controller;

import com.nai365.nart.blockchain.dto.*;
import com.nai365.nart.blockchain.service.AccountService;
import com.nai365.nart.blockchain.service.DDCService;
import com.nai365.nart.common.core.util.R;
import com.nai365.nart.common.security.annotation.Inner;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 账户
 *
 * @author luo guanglin
 * @date 2022-06-23 15:31:52
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/ddc")
@Api(value = "DDC", tags = "ddc")
public class DDCController {

	private final DDCService ddcService;


	/**
	 * 铸币
	 *
	 * @param coinDDCDto 铸币Dto
	 */
	@ApiOperation(value = "铸币")
	@PostMapping("/coin")
	public R<CoinDDCResultDto> coin(@RequestBody CoinDDCDto coinDDCDto) throws Exception {
		try {
			return R.ok(ddcService.coin(coinDDCDto));
		} catch (Exception e) {
			return R.failed(e.getMessage());
		}
	}

	/**
	 * 售卖，适用于一级市场
	 *
	 * @param sellInDto
	 */
	@ApiOperation(value = "售卖，适用一级市场售卖")
	@PostMapping("/sell")
	public R<SellOutDto> sell(@RequestBody SellInDto sellInDto) throws Exception {
		try {
			return R.ok(ddcService.sell(sellInDto));
		} catch (Exception e) {
			return R.failed(e.getMessage());
		}
	}

	/**
	 * 转账，适用于二级市场和转赠
	 *
	 * @param transferInDto
	 */
	@ApiOperation(value = "转账，适用二级市场和转赠")
	@PostMapping("/transfer")
	public R<TransferOutDto> transfer(@RequestBody TransferInDto transferInDto) throws Exception {
		try {
			return R.ok(ddcService.transfer(transferInDto));
		} catch (Exception e) {
			return R.failed(e.getMessage());
		}
	}

	/**
	 * 销毁，适用于回收和合成
	 *
	 * @param burnInDto
	 */
	@ApiOperation(value = "回收，适用回收和合成")
	@PostMapping("/burn")
	public R<BurnOutDto> burn(@RequestBody BurnInDto burnInDto) throws Exception {
		try {
			return R.ok(ddcService.burn(burnInDto));
		} catch (Exception e) {
			return R.failed(e.getMessage());
		}
	}

	@ApiOperation(value = "回收，适用回收和合成")
	@PostMapping("/setApprovalForAll")
	public R<String> setApprovalForAll() throws Exception {
		try {
			return R.ok(ddcService.setApprovalForAll());
		} catch (Exception e) {
			return R.failed(e.getMessage());
		}
	}

}
